package com.dailyblue.java.project.bookstore.controller;

import com.dailyblue.java.project.bookstore.service.ShoppingCartService;
import com.dailyblue.java.project.bookstore.util.JsonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/shopping")
public class ShoppingCartController {
    @Resource
    private ShoppingCartService shoppingCartService;

    @PostMapping("/{bookId}")
    public JsonResult add(@PathVariable String bookId, HttpServletRequest request) {
        return shoppingCartService.add(bookId, request);
    }

    @GetMapping
    public JsonResult find(HttpServletRequest request) {
        return shoppingCartService.find(request);
    }

    @PutMapping("/{bookId}/{number}")
    public JsonResult update(@PathVariable("bookId") String bookId, HttpServletRequest request, @PathVariable("number") int number) {
        return shoppingCartService.changeNumber(bookId, request, number);
    }

    @DeleteMapping
    public JsonResult remove(HttpServletRequest request, String... bookId) {
        return shoppingCartService.remove(request, bookId);
    }
}
